<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<base href="<%=basePath%>">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>${title}</title>
		<link rel="stylesheet" type="text/css" href="<c:url value='/resource/css/common.css'/>"/>
		<link rel="stylesheet" type="text/css" href="<c:url value='/resource/css/jquery.autocomplete.css'/>" />
		<script type="text/javascript" src="<c:url value='/resource/js/jquery-1.7.2.min.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/js/jquery.autocomplete.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/js/jquery.form.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/artdialog/artdialog.js?skin=${sys_theme}'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/artdialog/iframetools.js'/>"></script>	
		<script type="text/javascript" src="<c:url value='/resource/js/common.js'/>"></script>
		<script type="text/javascript">
			$(function(){
				$("#deptName").bind("click",openTree);
				$("#dept2Name").bind("click",openSubTree);
				if("${dept.deptId}".indexOf("00")==4)
				{
			        if("${dept.deptId}".length!=8)
			        {
				        $("#dept2Name").val("${dept.alias}");
				    }
				}
				else
				{
					if("${dept.deptId}".length!=6)
					{
				        $("#dept2Name").val("${dept.alias}");
				    }
				}
				/**
		 * 姓名自动补全
		 */
		if ($("#name").length > 0) {
			$("#name").autocomplete(parent.formateUrl("user/username.json"), {
				minChars : 0,
				max : 10, // 最大显示条数
				autoFill : false,
				dataType : "json", // 指定数据类型的渲染方式
				extraParams : {
					xm : function(){
						return $("#name").val();// url的参数传递
					}
				},
				parse : function(data) {
					var rows = [];
					var d = data.users;
					if(d){
						for ( var i = 0; i < d.length; i++) {
							rows[rows.length] = {
								data : d[i],
								value : d[i],
								result : d[i].xm
							};
						}
					}
					
					return rows;
				},
				formatItem : function(row, i, n) {
					if (row.bmName != null) {
						return row.name + "(" + row.bmName + ")";
					}
					if (row.bmName == null) {
						return row.name + "(" + row.deptName + ")";
					}
				}
			}).result(
					function(event, data, formatted) {
							$("#policeNum").val(data.policeNum);
							$("#name").val(data.name);
							$("#idCard").val(data.sfz);
						    $("#tel").val(data.contactphone);
						    $("#personid").val(data.personId);
					});
		}
		/**
		 * 警号自动补全
		 */
		if ($("#policeNum").length > 0) {
			$("#policeNum").autocomplete(
					parent.formateUrl("user/userinfo.json"), {
						minChars : 3,
						max : 10, // 最大显示条数
						autoFill : false,
						dataType : "json", // 指定数据类型的渲染方式
						extraParams : {
							policenum : function() {
								return $("#policeNum").val();// url的参数传递
							} 
						},
						parse : function(data) {
							var rows = [];
							var d = data.users;
							if(d){
								for ( var i = 0; i < d.length; i++) {
									rows[rows.length] = {
										data : d[i],
										value : d[i],
										result : d[i].policeNum
									};
								}	
							}
							
							return rows;
						},
						formatItem : function(row, i, n) {
							return row.policeNum + "(" + row.name + ")";
						}
					}).result(
					function(event, data, formatted) {
						$("#policeNum").val(data.policeNum);
						$("#name").val(data.name);
						$("#idCard").val(data.sfz);
						$("#tel").val(data.contactphone);
						$("#personid").val(data.personId);
					});
		          }
			})
			function openTree(){
				art.dialog.open("<c:url value='/common/open_radio_tree.jsp'/>",{
					title:"选择部门",
					lock : true,
					fixed : true,
					ok: function () {
						var iframe = this.iframe.contentWindow;
						if(!iframe.document.body){
							art.dialog.tips("正在加载，请稍候...",1500);
							return false;
						}
						iframe.sub_form();
						return false;
					},
					cancel: true
				});
			}
			function openSubTree(){
				var dw1=$("#deptId").val().substring(0, 8);
				if("${dept.deptId}".indexOf("00")!=4)
				{
				    dw1=$("#deptId").val().substring(0, 6);
				}
				art.dialog.open("<c:url value='/common/open_dept_tree.jsp?dw1="+dw1+"'/>",{
					title:"选择部门",
					lock : true,
					fixed : true,
					ok: function () {
						var iframe = this.iframe.contentWindow;
						if(!iframe.document.body){
							art.dialog.tips("正在加载，请稍候...",1500);
							return false;
						}
						iframe.sub_form();
						return false;
					},
					cancel: true
				});
			}
			function submitForm(pageIndex){
				if($("#poiceNum").val()==""){
					art.dialog.tips("请输入警号")
				}
				top.mask();
				$("#query_form").ajaxSubmit({
					type:"post",
					dataType:"json",
					success:function(data){
				top.unmask();
						switch(parseInt(data.result)){
							case 1:
								art.dialog.tips("编辑失败，警号重复！",3000);
								break;
							default:
								art.dialog.tips("编辑成功！",1.5);
								window.setTimeout(function(){
								window.parent.frames["ifrm_data"].frames["ifrm_deptlist"]._goto(pageIndex);
								art.dialog.close();
							},1500);
								break;
						}
					},
					error:function(){
				top.unmask();
						art.dialog.tips("编辑失败！",1.5);
					}
				});
			}
		</script>
	</head>


	<body style="margin:0 auto;overflow:hidden;" >
		<form method="post" id="query_form" action="<c:url value='/user/saveedit.json'/>" style="margin:0px;padding:0px;width:350px;">
			<table  style="margin:0px;padding:0px;">
				<tr>
					<td class="td_tit">警号:</td>
					<td><input style="width:254px;color:#ccc;" maxlength="10" value="${user.policeNum }" onblur="this.value=this.value.replace(/\s/g,'');" id="policeNum" type="text" name="policeNum" readonly="readonly"></input><span style="color:red">*</span></td>
				</tr>
				<tr>
					<td class="td_tit">姓名:</td>
					<td><input style="width:254px" maxlength="10" value="${user.name }" onblur="this.value=this.value.replace(/\s/g,'');" id="name" type="text" name="name"></input><span style="color:red">*</span></td>
				</tr>
				<tr>
					<td class="td_tit">所属单位:</td>
					<td>
						<input readonly="readonly" id="deptName" type="text" value="${deptTop.alias}" style="width:254px"/>
						<input type="hidden" id="deptId" name="deptId" value="${user.deptId}"/>
						<input type="hidden" name="dbId" value="${user.dbId}"/>
						<input name="userId" id="personid" type="hidden" value="${user.userId}"/>
					</td>
				</tr>
				<tr>
					<td class="td_tit">部门:</td>
					<td><input style="width:254px" maxlength="50" value="" onblur="this.value=this.value.replace(/\s/g,'');" id="dept2Name" type="text" name="dept2Name"></input></td>
				</tr>
				<tr>
					<td class="td_tit">身份证:</td>
					<td><input style="width:254px" maxlength="18" value="${user.idCard }"  id="idCard" type="text" name="idCard"></input></td>
				</tr>
				<tr>
					<td class="td_tit">联系电话:</td>
					<td><input style="width:254px"  id="tel" type="text" value="${user.tel }" name="tel"></input></td>
				</tr>
			</table>
		</form>
	</body>
</html>